package com.njtcedu.microblog.intranet.systemconfig.web;

import java.io.IOException;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.njtcedu.microblog.intranet.systemconfig.service.SystemConfigService;
import com.njtcedu.microblog.intranet.systemconfig.web.request.AdImagesRequest;
import com.njtcedu.microblog.intranet.systemconfig.web.response.AdImageResponse;

@Controller
@RequestMapping(value = "/intranet")
public class SystemConfigAjaxController {

	@Inject
	SystemConfigService systemConfigService;
	
	@RequestMapping(value = "/advertising", method = RequestMethod.POST)
	public String saveImageInfo (AdImagesRequest request) {
		systemConfigService.saveImageInfo(request);
		return "adimage_upload_secuss";
	}
	
	@RequestMapping(value = "/adimage/{imageName}", method = RequestMethod.POST )
	@ResponseBody
	public AdImageResponse uploadAdImage(@RequestParam(value = "imageFile", required = false) MultipartFile imageFile, HttpServletRequest request, @PathVariable("imageName") String imageName) throws IOException {
		String evePath = request.getServletContext().getRealPath("/");
		return systemConfigService.uploadAdImage(imageFile, evePath, imageName);
	}
}
